package daily_exercise;

import java.util.Arrays;

public class intToByte {
    
    

    public static void main(String[] args) {
        int number = 10000;
        byte[] bytes = toBytes(number);
        System.out.println(Arrays.toString(bytes));
        System.out.println(toInt(bytes));
        short s1 = 1; s1 += 1;

        int a = Integer.MAX_VALUE;
        int b = Integer.MAX_VALUE;
        int sum = a + b;
        System.out.println("a="+a+",b="+b + "sum="+sum);


    }

    private static int toInt(byte[] bytes) {
        int number = 0;
        for (int i = 0; i < 4; i++) {
            number += bytes[i] << i * 8;
        }
        return number;
    }

    private static byte[] toBytes(int number) {
        byte[] bytes = new byte[4];
        bytes[0] = (byte) number;
        bytes[1] = (byte) (number >> 8);
        bytes[2] = (byte) (number >> 16);
        bytes[3] = (byte) (number >> 24);
        return bytes;
    }
}
